package com.edu.controller.foodtype;

import com.edu.service.foodtype.FoodTypeService;
import com.edu.service.foodtype.FoodTypeServiceImpl;
import com.edu.utils.PageList;
import com.edu.utils.PageParam;
import com.edu.utils.ParamFormat;
import com.edu.utils.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author ZCN
 * @Date 2021/11/13 15:31
 * @Version 1.0
 **/
@WebServlet("/foodtype/pagelist")
public class PageListServlet extends HttpServlet {
    private FoodTypeService foodTypeService =new FoodTypeServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            ParamFormat.format(req, resp);
            // 获取参数
            Integer page = Integer.valueOf(req.getParameter("page"));
            Integer limit = Integer.valueOf(req.getParameter("limit"));
            PageParam pageParam = new PageParam(page, limit);
            PageList pageList = foodTypeService.pageList(pageParam);
            ResponseBody.success(resp,"success",pageList.getCount(),pageList.getData());
        } catch (Exception e) {
            e.printStackTrace();
            ResponseBody.failure(resp,e.getMessage());
        }
    }
}
